<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>投票页面</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.3/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/Chart.js/4.4.1/chart.min.js"></script>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
    <nav class="navbar navbar-dark bg-primary">
        <div class="container">
            <span class="navbar-brand mb-0 h1">
                <i class="fas fa-vote-yea"></i> 简易在线投票系统
            </span>
            <a class="btn btn-outline-light" href="/">
                <i class="fas fa-home"></i> 返回首页
            </a>
        </div>
    </nav>

    <div class="container mt-5">
        <div class="row">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">
                        <h4 id="pollTitle" class="mb-0">加载中...</h4>
                    </div>
                    <div class="card-body">
                        <form id="voteForm">
                            <div id="optionsContainer"></div>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-vote-yea"></i> 投票
                            </button>
                        </form>
                    </div>
                </div>

                <div class="card mt-4">
                    <div class="card-header">
                        <h5 class="mb-0">投票结果</h5>
                    </div>
                    <div class="card-body">
                        <canvas id="resultsChart" width="400" height="200"></canvas>
                        <div id="resultsTable" class="mt-3"></div>
                    </div>
                </div>
            </div>

            <div class="col-md-4">
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">分享投票</h5>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label class="form-label">投票链接</label>
                            <div class="input-group">
                                <input type="text" class="form-control" id="shareLink" readonly>
                                <button class="btn btn-outline-secondary" type="button" onclick="copyShareLink()">
                                    <i class="fas fa-copy"></i>
                                </button>
                            </div>
                        </div>
                        <div class="text-center">
                            <img id="shareQR" class="img-fluid" style="max-width: 200px;">
                        </div>
                    </div>
                </div>

                <div class="card mt-3">
                    <div class="card-header">
                        <h5 class="mb-0">投票统计</h5>
                    </div>
                    <div class="card-body">
                        <p><strong>总投票数：</strong> <span id="totalVotes">0</span></p>
                        <button class="btn btn-outline-primary w-100" onclick="refreshResults()">
                            <i class="fas fa-sync-alt"></i> 刷新结果
                        </button>
                        <button class="btn btn-outline-info w-100 mt-2" onclick="showAdminView()">
                            <i class="fas fa-eye"></i> 管理员视图
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 管理员视图模态框 -->
    <div class="modal fade" id="adminModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">管理员视图 - 详细投票记录</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <div id="adminContent">
                        <p>加载中...</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.3/js/bootstrap.bundle.min.js"></script>
    <script src="{{ url_for('static', filename='js/poll.js') }}"></script>
</body>
</html>
